package com.ruoyi.result.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.result.domain.ResultTask;
import com.ruoyi.result.service.IResultTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成果申报Controller
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Api("成果申报管理")
@RestController
@RequestMapping("/result/task")
public class ResultTaskController extends BaseController
{
    @Autowired
    private IResultTaskService resultTaskService;

    /**
     * 查询成果申报列表
     */
    @ApiOperation("查询成果申报列表")   
    @PreAuthorize("@ss.hasPermi('result:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResultTask resultTask)
    {
        startPage();
        List<ResultTask> list = resultTaskService.selectResultTaskList(resultTask);
        return getDataTable(list);
    }

    /**
     * 导出成果申报列表
     */
    @ApiOperation("导出成果申报列表")    
    @PreAuthorize("@ss.hasPermi('result:task:export')")
    @Log(title = "成果申报", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ResultTask resultTask)
    {
        List<ResultTask> list = resultTaskService.selectResultTaskList(resultTask);
        ExcelUtil<ResultTask> util = new ExcelUtil<ResultTask>(ResultTask.class);
        return util.exportExcel(list, "task");
    }

    /**
     * 获取成果申报详细信息
     */
    @ApiOperation("获取成果申报详细信息")
    @ApiImplicitParam(name = "id", value = "成果申报ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('result:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(resultTaskService.selectResultTaskById(id));
    }

    /**
     * 新增成果申报
     */
    @ApiOperation("新增成果申报")
    @PreAuthorize("@ss.hasPermi('result:task:add')")
    @Log(title = "成果申报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResultTask resultTask)
    {
        return toAjax(resultTaskService.insertResultTask(resultTask));
    }

    /**
     * 修改成果申报
     */
    @ApiOperation("修改成果申报")  
    @PreAuthorize("@ss.hasPermi('result:task:edit')")
    @Log(title = "成果申报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResultTask resultTask)
    {
        return toAjax(resultTaskService.updateResultTask(resultTask));
    }

    /**
     * 删除成果申报
     */
    @ApiOperation("删除成果申报")
    @ApiImplicitParam(name = "id", value = "成果申报ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('result:task:remove')")
    @Log(title = "成果申报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resultTaskService.deleteResultTaskByIds(ids));
    }
}
